//package com.yunhe.option.controller.data;
//
//import com.yunhe.common.annotation.OperationRecord;
//import com.yunhe.common.constant.SystemConsts;
//import com.yunhe.option.domain.data.Price;
//import com.yunhe.common.exception.ArgumentErrorException;
//import com.yunhe.common.exception.ObjectNotFoundException;
//import com.yunhe.common.exception.UniqueConstraintsException;
//import com.yunhe.common.model.DomainList;
//import com.yunhe.common.model.PageParam;
//import com.yunhe.common.model.ResultObject;
//import com.yunhe.option.service.data.PriceService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.format.annotation.DateTimeFormat;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 价格Controller
// * @author liuronglei
// */
//@Api(value = "price", description = "价格维护", tags = {"Data_Price"})
//@RestController
//@RequestMapping("/prices")
//public class PriceController {
//    @Autowired
//    private PriceService priceService;
//
//    /**
//     * 新增价格
//     * @param price 价格对象
//     */
//    @ApiOperation("新增价格")
//    @RequestMapping(method = RequestMethod.POST)
//    @OperationRecord(menu = "参数配置", actionType = SystemConsts.ACTION.ADD)
//    public ResponseEntity<ResultObject> post(
//            @RequestBody Price price)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Price newPrice = priceService.createPrice(price);
//        return new ResponseEntity<>(new ResultObject<>(newPrice), HttpStatus.OK);
//    }
//
//    /**
//     * 批量新增价格
//     * @param domainList 价格对象列表
//     */
//    @ApiOperation("批量新增价格")
//    @RequestMapping(value = "/batch", method = RequestMethod.POST)
//    @OperationRecord(menu = "参数配置", actionType = SystemConsts.ACTION.ADD)
//    public ResponseEntity<ResultObject> batchPost(
//            @RequestBody DomainList<Price> domainList)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        List<Price> priceList = domainList.getList();
//        Iterable<Price> newPrices = priceService.createPrice(priceList);
//        return new ResponseEntity<>(new ResultObject<>(newPrices), HttpStatus.OK);
//    }
//
//    /**
//     * 根据地区代码和类型代码删除价格
//     * @param areaCode 地区代码
//     * @param typeCode 类型代码
//     */
//    @ApiOperation("根据地区代码和类型代码删除价格")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "areaCode", value = "地区代码", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "typeCode", value = "类型代码", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/areaCode/{areaCode}/typeCode/{typeCode}", method = RequestMethod.DELETE)
//    @OperationRecord(menu = "参数配置", actionType = SystemConsts.ACTION.DELETE)
//    public ResponseEntity<ResultObject> delete(
//            @PathVariable("areaCode") Long areaCode,
//            @PathVariable("typeCode") Long typeCode) {
//        Long result = priceService.deletePriceByAreaCodeAndTypeCode(areaCode, typeCode);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 根据时间范围更新价格
//     * @param areaCode 地区代码
//     * @param typeCode 类型代码
//     * @param dtime 时间范围
//     * @param val 值
//     */
//    @ApiOperation("更新价格（根据时间范围）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "areaCode", value = "地区代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "类型代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "dtime", value = "时间，如“2017-12-06 00:00:00,2017-12-06 10:00:00”", required = true, dataType = "date", paramType = "query"),
//            @ApiImplicitParam(name = "val", value = "值", required = true, dataType = "double", paramType = "query")
//    })
//    @RequestMapping(value = "/byRange", method = RequestMethod.PATCH)
//    @OperationRecord(menu = "参数配置", actionType = SystemConsts.ACTION.EDIT)
//    public ResponseEntity<ResultObject> updatePrices(
//            @RequestParam("areaCode") Long areaCode,
//            @RequestParam("typeCode") Long typeCode,
//            @RequestParam("dtime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") List<Date> dtime,
//            @RequestParam("val") Double val) {
//        List<Price> results = priceService.updatePrices(areaCode, typeCode, dtime, val);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 更新价格
//     * @param areaCode 地区代码
//     * @param typeCode 类型代码
//     * @param dtime 时间范围
//     * @param val 值
//     */
//    @ApiOperation("更新价格")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "areaCode", value = "地区代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "类型代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "dtime", value = "时间，如“2017-12-06 00:00:00”", required = true, dataType = "date", paramType = "query"),
//            @ApiImplicitParam(name = "val", value = "值", required = true, dataType = "double", paramType = "query")
//    })
//    @RequestMapping(method = RequestMethod.PATCH)
//    @OperationRecord(menu = "参数配置", actionType = SystemConsts.ACTION.EDIT)
//    public ResponseEntity<ResultObject> updatePrice(
//            @RequestParam("areaCode") Long areaCode,
//            @RequestParam("typeCode") Long typeCode,
//            @RequestParam("dtime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date dtime,
//            @RequestParam("val") Double val)
//            throws UniqueConstraintsException, ArgumentErrorException {
//        Price result = priceService.updatePrice(areaCode, typeCode, dtime, val);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 根据条件获得价格列表
//     * @param areaCode 地区代码
//     * @param typeCode 类型代码
//     * @param dtime 时间范围
//     */
//    @ApiOperation("根据条件获得价格列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "areaCode", value = "地区代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "typeCode", value = "类型代码", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "dtime", value = "时间范围，如“2018-05-29 00:00:00,2018-05-29 23:45:00”", dataType = "Date", paramType = "query")
//    })
//    @RequestMapping(method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> search(
//            @RequestParam("areaCode") Long areaCode,
//            @RequestParam("typeCode") Long typeCode,
//            @RequestParam("dtime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Optional<List<Date>> dtime,
//            @ModelAttribute PageParam pageParam) {
//        List<Date> time = null;
//        if (dtime.isPresent()) {
//            time = new ArrayList<>();
//            for (Date dtimeItem : dtime.get()) {
//                time.add(dtimeItem);
//            }
//        }
//        Iterable<Price> results = priceService.findPrices(areaCode, typeCode, time, pageParam);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//}